package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.SysBlessEntity;
import io.renren.service.SysBlessService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-04-28 08:56:59
 */
@Controller
@RequestMapping("sysbless")
public class SysBlessController {
    @Autowired
    private SysBlessService sysBlessService;

    @RequestMapping("/sysbless.html")
    public String list() {
        return "sysbless/sysbless.html";
    }

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/list")
    @RequiresPermissions("sysbless:list")
    public R list(Integer page, Integer limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("offset", (page - 1) * limit);
        map.put("limit", limit);

        //查询列表数据
        List<SysBlessEntity> sysBlessList = sysBlessService.queryList(map);
        int total = sysBlessService.queryTotal(map);

        PageUtils pageUtil = new PageUtils(sysBlessList, total, limit, page);

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @ResponseBody
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sysbless:info")
    public R info(@PathVariable("id") Integer id) {
        SysBlessEntity sysBless = sysBlessService.queryObject(id);

        return R.ok().put("sysBless", sysBless);
    }

    /**
     * 保存
     */
    @ResponseBody
    @RequestMapping("/save")
    @RequiresPermissions("sysbless:save")
    public R save(@RequestBody SysBlessEntity sysBless) {

        sysBlessService.save(sysBless);
        return R.ok();
    }

    @ResponseBody
    @RequestMapping("/ajaxSave")
    public R ajaxSave(@RequestBody SysBlessEntity sysBless) {
        sysBlessService.save(sysBless);
        return R.ok();
    }


    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("sysbless:update")
    public R update(@RequestBody SysBlessEntity sysBless) {
        sysBlessService.update(sysBless);

        return R.ok();
    }

    /**
     * 删除
     */
    @ResponseBody
    @RequestMapping("/delete")
    @RequiresPermissions("sysbless:delete")
    public R delete(@RequestBody Integer[] ids) {
        sysBlessService.deleteBatch(ids);

        return R.ok();
    }

}
